home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: Henry Cross <hcross@ix.netcom.com>
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: Speed of C program vs. Speed of Pascal program
- Date: Wed, 13 Mar 1996 19:44:31 -0800
- Organization: i586 Box @Irvine, Ca.
- Message-ID: <3147961F.420@ix.netcom.com>
- References: <4hsf8p$c5d@caesar.ultra.net> <4hum94$npg@challenge.tcel.com>
- NNTP-Posting-Host: irv-ca12-23.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-NETCOM-Date: Wed Mar 13 9:45:45 PM CST 1996
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Ritchie Annand wrote:
- >
- > In article <4hsf8p$c5d@caesar.ultra.net>,
- > kbrady@ultranet.com (Ken Brady) wrote:
- > >I recently began learning to program in C/C++ after many years
- > >of using Borland Turbo Pascal (v6.0). I have been porting a data analysis
- > >program into C/C++, and notice that a subroutinefor reading large tables of
- > >numbers (ASCII) and loading these numbers into (binary) arrays proceeds much
- > >more rapidly in my C program than in my Pascal program. For one large
- > table,
- > >my Pascal program requires about 10 s to load the table, while the C program
- > >loads it in less than 1 second.
- > >
- > >The I/O algorithms in these programs are essentially identical. I deduce
- > >that the C atof function is much faster than the Pascal Val function. Is
- > >this typical?
- > >
- > >My C/C++ compiler is Watcom 10.5, running under OS/2.
- >
- > Actually, that depends...
- >
- > It's quite possible atof is faster than Val - they are both library
- > functions, after all, but generally speaking, you won't get a 10:1 speed ramp
- > between the two from that sort of difference.
- >
- > It'd be my guess that you're using unbuffered Pascal I/O versus buffered C
- > I/O... I've found that to be where most file-access differences lie:
- >
- > If your Pascal program uses:
- > var
- > f : Text;
- >
- > Then it's buffered (but not with a very large buffer - you can set it,
- > though)
- >
- > If you use:
- > var
- > f : File;
- > or
- > f : File of Char;
- > or
- > f : File of MyRecord;
- >
- > Then it's unbuffered.
- >
- > With f : File, though, you do have the option of doing BlockRead and
- > BlockWrite. Reset(f,SizeOf(MyRecord)) - if you're using a flat file of
- > MyRecords, and BlockRead(f,MyRecordArray,NumberOfRecords,ActualRecordsRead) -
- > that will give you some mighty good throughput ;)
-
- So will setvbuff() :)
-
- regards,
- H.Cross
- hcross@ix.netcom.com
-